home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / cdrtools-1.10 / cdrecord / scsi_scan.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-07-30  |  4.4 KB  |  194 lines

  1. /* @(#)scsi_scan.c    1.9 00/07/30 Copyright 1997 J. Schilling */
  2. #ifndef lint
  3. static    char sccsid[] =
  4.     "@(#)scsi_scan.c    1.9 00/07/30 Copyright 1997 J. Schilling";
  5. #endif
  6. /*
  7.  *    Scan SCSI Bus.
  8.  *    Stolen from sformat. Need a more general form to
  9.  *    re-use it in sformat too.
  10.  *
  11.  *    Copyright (c) 1997 J. Schilling
  12.  */
  13. /*
  14.  * This program is free software; you can redistribute it and/or modify
  15.  * it under the terms of the GNU General Public License as published by
  16.  * the Free Software Foundation; either version 2, or (at your option)
  17.  * any later version.
  18.  *
  19.  * This program is distributed in the hope that it will be useful,
  20.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22.  * GNU General Public License for more details.
  23.  *
  24.  * You should have received a copy of the GNU General Public License
  25.  * along with this program; see the file COPYING.  If not, write to
  26.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  27.  */
  28.  
  29. #include <stdxlib.h>
  30. #include <standard.h>
  31. #include <btorder.h>
  32. #include <errno.h>
  33. #include <schily.h>
  34.  
  35. #include <scg/scgcmd.h>
  36. #include <scg/scsidefs.h>
  37. #include <scg/scsireg.h>
  38. #include <scg/scsitransp.h>
  39.  
  40. #include "scsi_scan.h"
  41. #include "cdrecord.h"
  42.  
  43. LOCAL    void    print_product        __PR((struct scsi_inquiry *ip));
  44. EXPORT    void    select_target        __PR((SCSI *scgp));
  45. LOCAL    void    select_unit        __PR((SCSI *scgp));
  46.  
  47. LOCAL void
  48. print_product(ip)
  49.     struct    scsi_inquiry *ip;
  50. {
  51.     printf("'%.8s' ", ip->info);
  52.     printf("'%.16s' ", ip->ident);
  53.     printf("'%.4s' ", ip->revision);
  54.     if (ip->add_len < 31) {
  55.         printf("NON CCS ");
  56.     }
  57.     scg_printdev(ip);
  58. }
  59.  
  60. EXPORT void
  61. select_target(scgp)
  62.     SCSI    *scgp;
  63. {
  64.     int    initiator;
  65.     int    cscsibus = scgp->scsibus;
  66.     int    ctarget =  scgp->target;
  67.     int    clun    =  scgp->lun;
  68.     int    n;
  69.     int    low    = -1;
  70.     int    high    = -1;
  71.     BOOL    have_tgt;
  72.  
  73.     scgp->silent++;
  74.  
  75.     for (scgp->scsibus=0; scgp->scsibus < 16; scgp->scsibus++) {
  76.         if (!scg_havebus(scgp, scgp->scsibus))
  77.             continue;
  78.  
  79.         initiator = scg_initiator_id(scgp);
  80.         printf("scsibus%d:\n", scgp->scsibus);
  81.  
  82.         for (scgp->target=0, scgp->lun=0; scgp->target < 16; scgp->target++) {
  83.             n = scgp->scsibus*100 + scgp->target;
  84.         
  85.             have_tgt = unit_ready(scgp) || scgp->scmd->error != SCG_FATAL;
  86.  
  87.  
  88.             if (!have_tgt && scgp->target > 7) {
  89.                 if (scgp->scmd->ux_errno == EINVAL)
  90.                     break;
  91. /*                if ((high%100) < 8)*/
  92.                 continue;
  93.             }
  94.  
  95. /*            if (print_disknames(scgp->scsibus, scgp->target, -1) < 8)*/
  96. /*                printf("\t");*/
  97.             printf("\t");
  98.             if (printf("%d,%d,%d", scgp->scsibus, scgp->target, scgp->lun) < 8)
  99.                 printf("\t");
  100.             else
  101.                 printf(" ");
  102.             printf("%3d) ", n);
  103.             if (scgp->target == initiator) {
  104.                 printf("HOST ADAPTOR\n");
  105.                 continue;
  106.             }
  107.             if (!have_tgt) {
  108.                 printf("*\n");
  109.                 continue;
  110.             }
  111.             if (low < 0)
  112.                 low = n;
  113.             high = n;
  114.  
  115.             getdev(scgp, FALSE);
  116.             print_product(scgp->inq);
  117.         }
  118.     }
  119.     scgp->silent--;
  120.  
  121.     if (low < 0)
  122.         comerrno(EX_BAD, "No target found.\n");
  123.     n = -1;
  124. /*    getint("Select target", &n, low, high); */
  125. exit(0);
  126.     scgp->scsibus = n/10;
  127.     scgp->target = n%10;
  128.     select_unit(scgp);
  129.  
  130.     scgp->scsibus    = cscsibus;
  131.     scgp->target    = ctarget;
  132.     scgp->lun    = clun;
  133. }
  134.  
  135. LOCAL void
  136. select_unit(scgp)
  137.     SCSI    *scgp;
  138. {
  139.     int    initiator;
  140.     int    clun    = scgp->lun;
  141.     int    low    = -1;
  142.     int    high    = -1;
  143.  
  144.     scgp->silent++;
  145.  
  146.     printf("scsibus%d target %d:\n", scgp->scsibus, scgp->target);
  147.  
  148.     initiator = scg_initiator_id(scgp);
  149.     for (scgp->lun=0; scgp->lun < 8; scgp->lun++) {
  150.  
  151. /*        if (print_disknames(scgp->scsibus, scgp->target, scgp->lun) < 8)*/
  152. /*            printf("\t");*/
  153.  
  154.         printf("\t");
  155.         if (printf("%d,%d,%d", scgp->scsibus, scgp->target, scgp->lun) < 8)
  156.             printf("\t");
  157.         else
  158.             printf(" ");
  159.         printf("%3d) ", scgp->lun);
  160.         if (scgp->target == initiator) {
  161.             printf("HOST ADAPTOR\n");
  162.             continue;
  163.         }
  164.         if (!unit_ready(scgp) && scgp->scmd->error == SCG_FATAL) {
  165.             printf("*\n");
  166.             continue;
  167.         }
  168.         if (unit_ready(scgp)) {
  169.             /* non extended sense illegal lun */
  170.             if (scgp->scmd->sense.code == 0x25) {
  171.                 printf("BAD UNIT\n");
  172.                 continue;
  173.             }
  174.         }
  175.         if (low < 0)
  176.             low = scgp->lun;
  177.         high = scgp->lun;
  178.  
  179.         getdev(scgp, FALSE);
  180.         print_product(scgp->inq);
  181.     }
  182.     scgp->silent--;
  183.  
  184.     if (low < 0)
  185.         comerrno(EX_BAD, "No lun found.\n");
  186.     scgp->lun = -1;
  187. /*    getint("Select lun", &scgp->lun, low, high); */
  188. exit(0);
  189. /*    format_one();*/
  190.     
  191.     scgp->lun    = clun;
  192. }
  193.  
  194.